Telegram Group & Telegram Channel
18. Program to Find GCDLCM.

import java.util.Scanner;

class GCDLCM
{
public static void main(String args[])
{
int x, y;
Scanner sc = new Scanner(System.in);

System.out.println("Enter the two numbers: ");
x = sc.nextInt();
y = sc.nextInt();

System.out.println("GCD of two numbers is : " + gcd(x, y));
System.out.println("LCM of two numbers is : " + lcm(x, y));
}

static int gcd(int x, int y)
{
int r = 0, a, b;
a = (x > y) ? x : y; // a is greater number
b = (x < y) ? x : y; // b is smaller number

r = b;
while (a % b != 0)
{
r = a % b;
a = b;
b = r;
}
return r;
}

static int lcm(int x, int y)
{
int a;
a = (x > y) ? x : y; // a is greater number
while (true)
{
if (a % x == 0 && a % y == 0)
{
return a;
}
++a;
}
}
}

@java_codings



tg-me.com/java_codings/27
Create:
Last Update:

18. Program to Find GCDLCM.

import java.util.Scanner;

class GCDLCM
{
public static void main(String args[])
{
int x, y;
Scanner sc = new Scanner(System.in);

System.out.println("Enter the two numbers: ");
x = sc.nextInt();
y = sc.nextInt();

System.out.println("GCD of two numbers is : " + gcd(x, y));
System.out.println("LCM of two numbers is : " + lcm(x, y));
}

static int gcd(int x, int y)
{
int r = 0, a, b;
a = (x > y) ? x : y; // a is greater number
b = (x < y) ? x : y; // b is smaller number

r = b;
while (a % b != 0)
{
r = a % b;
a = b;
b = r;
}
return r;
}

static int lcm(int x, int y)
{
int a;
a = (x > y) ? x : y; // a is greater number
while (true)
{
if (a % x == 0 && a % y == 0)
{
return a;
}
++a;
}
}
}

@java_codings

BY Advance Java πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/java_codings/27

View MORE
Open in Telegram


Advance Java ‍ Telegram | DID YOU KNOW?

Date: |

Telegram today rolling out an update which brings with it several new features.The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations.

NEWS: Telegram supports Facetime video calls NOW!

Secure video calling is in high demand. As an alternative to Zoom, many people are using end-to-end encrypted apps such as WhatsApp, FaceTime or Signal to speak to friends and family face-to-face since coronavirus lockdowns started to take place across the world. There’s another optionβ€”secure communications app Telegram just added video calling to its feature set, available on both iOS and Android. The new feature is also super secureβ€”like Signal and WhatsApp and unlike Zoom (yet), video calls will be end-to-end encrypted.

Advance Java ‍ from vn


Telegram Advance Java πŸ‘¨β€πŸ’»
FROM USA